Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming
Creating a class instance using the NEW statement
The
NEWstatement is used to create an instance of a class. At run time, theNEWstatement locates the named class on thePROPATHusing the package information in the class type name and invokes the constructor to create a new instance of the class. The instantiated class is also referred to as a class-based object. TheNEWstatement assigns a reference for the new class instance to an object reference variable.This is the syntax for instantiating a class using the
NEWstatement:
Element descriptions for this syntax diagram follow:
object-referenceThe name of a variable, parameter, or temp-table field appropriately defined as a class type. The class type name used in the
Note: Ifobject-referencedefinition must follow the rules fortype-name.object-referenceis a temp-table field, its class type name can only beProgress.Lang.Object, the Progress root class. For more information on the Progress root class, see the "Using the root class — Progress.Lang.Object" section.type-nameThe type name of the class to instantiate. For more information type names, see the "Using the CLASS construct" section
This type name must also match the type name for one of the following classes involved in the class hierarchy of the class type name used to define
object-reference:[parameter[ ,parameter] ... ]The parameters of the constructor. For more information on the syntax of
parameter, see the “Parameter passing syntax” reference entry in OpenEdge Development: Progress 4GL Reference .Whenever an instance of a class is created, the constructor of the instantiated class, as well as the constructors of any super classes in its class hierarchy are run. The instantiated object gets its own copy of the
PROTECTEDandPUBLICdata members defined in the class hierarchy. Thus, just as with persistent procedures, each instance of a class is a separate entity with its own instance data.This example, from the
Mainclass described previously (see the "Defining an object reference as a variable" section), creates instances of two sample classes in its constructor:
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |